package cn.iocoder.yudao.module.vote.dal.mysql.voteconfig;

import java.util.*;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.vote.dal.dataobject.voteconfig.VoteConfigDO;
import cn.iocoder.yudao.module.vote.dal.dataobject.voteuserresult.VoteUserResultDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.vote.controller.admin.voteconfig.vo.*;

/**
 * 优秀最大比例配置信息 Mapper
 *
 * @author moving
 */
@Mapper
public interface VoteConfigMapper extends BaseMapperX<VoteConfigDO> {

    default PageResult<VoteConfigDO> selectPage(VoteConfigPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<VoteConfigDO>()
                .eqIfPresent(VoteConfigDO::getVoteId, reqVO.getVoteId())
                .eqIfPresent(VoteConfigDO::getVoteType, reqVO.getVoteType())
                .eqIfPresent(VoteConfigDO::getExcellentMaxCount, reqVO.getExcellentMaxCount())
                .eqIfPresent(VoteConfigDO::getSpecialVote, reqVO.getSpecialVote())
                .eqIfPresent(VoteConfigDO::getSpecialMaxCount, reqVO.getSpecialMaxCount())
                .likeIfPresent(VoteConfigDO::getVoteName, reqVO.getVoteName())
                .betweenIfPresent(VoteConfigDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .notIn(CollUtil.isNotEmpty(reqVO.getNoInVoteType()),VoteConfigDO::getVoteType,reqVO.getNoInVoteType())
                .orderByDesc(VoteConfigDO::getId));
    }

    default List<VoteConfigDO> selectList(VoteConfigExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<VoteConfigDO>()
                .eqIfPresent(VoteConfigDO::getVoteId, reqVO.getVoteId())
                .eqIfPresent(VoteConfigDO::getVoteType, reqVO.getVoteType())
                .eqIfPresent(VoteConfigDO::getExcellentMaxCount, reqVO.getExcellentMaxCount())
                .eqIfPresent(VoteConfigDO::getSpecialVote, reqVO.getSpecialVote())
                .eqIfPresent(VoteConfigDO::getSpecialMaxCount, reqVO.getSpecialMaxCount())
                .likeIfPresent(VoteConfigDO::getVoteName, reqVO.getVoteName())
                .betweenIfPresent(VoteConfigDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(VoteConfigDO::getId));
    }

    default VoteConfigDO selectByVoteId(Integer voteId) {
        return selectOne(new LambdaQueryWrapper<VoteConfigDO>()
                .eq(VoteConfigDO::getVoteId, voteId)
        );
    }


    default VoteConfigDO select(Integer voteId,Integer deptId,Long id) {
        return selectOne(new LambdaQueryWrapperX<VoteConfigDO>()
                .neIfPresent(VoteConfigDO::getId,id)
                .eqIfPresent(VoteConfigDO::getVoteId, voteId)
                .eqIfPresent(VoteConfigDO::getDeptId,deptId)
                .last("limit 1")
        );
    }

    /**
     * 获取全局默认配置
     * @param voteType
     * @return
     */
    VoteConfigDO getDefaultConfig(Integer voteType);

}
